<?php

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap {

    protected function _initRouter() {

		/**
		 * Si $methodePHP == 1 alors la méthode utilisés pour charger les routes sera en php, directement depuis le bootstrap.
		 * Si $methodePHP == 0 alors la méthode utilisée pour charger les routes se fera grace au fichier application.ini
		 */
        $methodePHP = 1;
		
        if ($methodePHP) {
            $front = $this->bootstrap('FrontController')->getResource('FrontController');
            $router = $front->getRouter();
            $routingTable = array(
                'accueil' => array('key' => 'accueil', 'defaults' => array('controller' => 'index', 'action' => 'index')),
                'apropos' => array('key' => 'a-propos', 'defaults' => array('controller' => 'index', 'action' => 'apropos')),
                'contact' => array('key' => 'contact/:topic', 'defaults' => array('controller' => 'index', 'action' => 'contact', 'topic' => 'Topic par defaut')),
                'membres' => array('key' => 'membres/:id/*', 'defaults' => array('controller' => 'index', 'action' => 'membres'), 'reqs' => array('id' => '\d+'))
            );
            foreach ($routingTable as $key => $value) {
                $reqs = isset($value['reqs']) ? $value['reqs'] : null;
                $route = new Zend_Controller_Router_Route($value['key'], $value['defaults'], $reqs);
                $router->addRoute($key, $route);
            }

            $routeRegex = new Zend_Controller_Router_Route_Regex('teams/(\d+)-(\w+)', array('controller' => 'index', 'action' => 'teams'), array(1 => 'id', 2 => 'name'), 'teams/%d-%s');
            $router->addRoute('teams', $routeRegex);
        } else {
            $front = $this->bootstrap('FrontController')->getResource('FrontController');
            $router = $front->getRouter();
            $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'production');
            $routing = new Zend_Controller_Router_Rewrite();
            $routing->addConfig($config, 'routes');
            $front->setRouter($routing);
        }
    }

}

